<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教材版本与知识点关联管理</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.8/dist/chart.umd.min.js"></script>
    
    <!-- Tailwind 配置 -->
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#165DFF',
                        secondary: '#36CBCB',
                        accent: '#FF7D00',
                        neutral: '#F5F7FA',
                        'neutral-dark': '#4E5969',
                        success: '#00B42A',
                        warning: '#FF7D00',
                        danger: '#F53F3F',
                    },
                    fontFamily: {
                        inter: ['Inter', 'system-ui', 'sans-serif'],
                    },
                }
            }
        }
    </script>
    
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .scrollbar-hide {
                -ms-overflow-style: none;
                scrollbar-width: none;
            }
            .scrollbar-hide::-webkit-scrollbar {
                display: none;
            }
            .text-shadow {
                text-shadow: 0 2px 4px rgba(0,0,0,0.1);
            }
            .tree-line {
                @apply border-l-2 border-dashed border-gray-200 ml-3 pl-4;
            }
            .hover-scale {
                @apply transition-transform duration-300 hover:scale-105;
            }
            .fade-in {
                animation: fadeIn 0.5s ease-in-out;
            }
            @keyframes fadeIn {
                from { opacity: 0; transform: translateY(10px); }
                to { opacity: 1; transform: translateY(0); }
            }
        }
    </style>
</head>
<body class="bg-gray-50 font-inter text-gray-800 min-h-screen flex flex-col">
    <!-- 顶部导航栏 -->
    <header class="bg-white shadow-sm sticky top-0 z-50 transition-all duration-300">
        <div class="container mx-auto px-0 py-3 flex items-center justify-between">
            <div class="flex items-center space-x-2">
                <button id="sidebar-toggle" class="lg:hidden text-gray-500 hover:text-primary transition-colors">
                    <i class="fa fa-bars text-xl"></i>
                </button>
                <h1 class="text-xl font-bold text-primary flex items-center">
                    <i class="fa fa-book mr-2"></i>
                    <span>睿途题库</span>
                </h1>
            </div>

            <div class="hidden md:flex items-center space-x-6">
                <!-- 控制面板 -->
                <div class="relative group">
                    <a href="#" class="text-gray-600 hover:text-primary transition-colors flex items-center">
                        <i class="fa fa-tachometer mr-1"></i> 控制面板
                        <i class="fa fa-angle-down ml-1 text-xs"></i>
                    </a>
                    <div class="absolute top-full left-0 mt-1 w-48 bg-white shadow-lg rounded-lg border border-gray-200 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-50">
                        <div class="py-2">
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-dashboard mr-2"></i> 仪表盘
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-chart-line mr-2"></i> 数据概览
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-tasks mr-2"></i> 任务管理
                            </a>
                        </div>
                    </div>
                </div>

                <!-- 教材管理 -->
                <div class="relative group">
                    <a href="#" class="text-gray-600 font-medium border-b-2 border-primary pb-1 flex items-center">
                        <i class="fa fa-book mr-1"></i> 教材管理
                        <i class="fa fa-angle-down ml-1 text-xs"></i>
                    </a>
                    <div class="absolute top-full left-0 mt-1 w-48 bg-white shadow-lg rounded-lg border border-gray-200 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-50">
                        <div class="py-2">
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-list mr-2"></i> 版本管理
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-sitemap mr-2"></i> 章节管理
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-lightbulb-o mr-2"></i> 知识点管理
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-primary bg-primary/10 font-medium">
                                <i class="fa fa-exchange mr-2"></i> 版本对比
                            </a>
                        </div>
                    </div>
                </div>

                <!-- 题库管理 -->
                <div class="relative group">
                    <a href="#" class="text-gray-600 hover:text-primary transition-colors flex items-center">
                        <i class="fa fa-database mr-1"></i> 题库管理
                        <i class="fa fa-angle-down ml-1 text-xs"></i>
                    </a>
                    <div class="absolute top-full left-0 mt-1 w-48 bg-white shadow-lg rounded-lg border border-gray-200 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-50">
                        <div class="py-2">
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-question-circle mr-2"></i> 题目管理
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-tags mr-2"></i> 标签管理
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-filter mr-2"></i> 筛选规则
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-upload mr-2"></i> 批量导入
                            </a>
                        </div>
                    </div>
                </div>

                <!-- 组卷系统 -->
                <div class="relative group">
                    <a href="#" class="text-gray-600 hover:text-primary transition-colors flex items-center">
                        <i class="fa fa-files-o mr-1"></i> 组卷系统
                        <i class="fa fa-angle-down ml-1 text-xs"></i>
                    </a>
                    <div class="absolute top-full left-0 mt-1 w-48 bg-white shadow-lg rounded-lg border border-gray-200 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-50">
                        <div class="py-2">
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-magic mr-2"></i> 智能组卷
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-edit mr-2"></i> 手动组卷
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-copy mr-2"></i> 试卷模板
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-history mr-2"></i> 历史试卷
                            </a>
                        </div>
                    </div>
                </div>

                <!-- 数据分析 -->
                <div class="relative group">
                    <a href="#" class="text-gray-600 hover:text-primary transition-colors flex items-center">
                        <i class="fa fa-bar-chart mr-1"></i> 数据分析
                        <i class="fa fa-angle-down ml-1 text-xs"></i>
                    </a>
                    <div class="absolute top-full left-0 mt-1 w-48 bg-white shadow-lg rounded-lg border border-gray-200 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-50">
                        <div class="py-2">
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-chart-pie mr-2"></i> 学习分析
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-chart-bar mr-2"></i> 成绩统计
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-chart-line mr-2"></i> 趋势分析
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-file-text mr-2"></i> 报告生成
                            </a>
                        </div>
                    </div>
                </div>

                <!-- 系统设置 -->
                <div class="relative group">
                    <a href="#" class="text-gray-600 hover:text-primary transition-colors flex items-center">
                        <i class="fa fa-cog mr-1"></i> 系统设置
                        <i class="fa fa-angle-down ml-1 text-xs"></i>
                    </a>
                    <div class="absolute top-full left-0 mt-1 w-48 bg-white shadow-lg rounded-lg border border-gray-200 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-50">
                        <div class="py-2">
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-users mr-2"></i> 用户管理
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-shield mr-2"></i> 权限设置
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-database mr-2"></i> 数据备份
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-primary transition-colors">
                                <i class="fa fa-cogs mr-2"></i> 系统配置
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="flex items-center space-x-4">
                <div class="relative">
                    <input type="text" placeholder="搜索教材、章节或知识点..."
                           class="pl-10 pr-4 py-2 rounded-full bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary/20 transition-all w-40 lg:w-64">
                    <i class="fa fa-search absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                </div>

                <div class="relative">
                    <button class="text-gray-500 hover:text-primary transition-colors">
                        <i class="fa fa-bell text-xl"></i>
                        <span class="absolute -top-1 -right-1 bg-danger text-white text-xs rounded-full h-4 w-4 flex items-center justify-center">3</span>
                    </button>
                </div>

                <div class="flex items-center space-x-2 cursor-pointer group">
                    <img src="https://picsum.photos/id/64/40/40" alt="用户头像" class="w-8 h-8 rounded-full object-cover border-2 border-transparent group-hover:border-primary transition-all">
                    <span class="hidden md:inline font-medium">张老师</span>
                    <i class="fa fa-angle-down text-gray-400 group-hover:text-primary transition-colors"></i>
                </div>
            </div>
        </div>
    </header>

    <div class="flex flex-1 overflow-hidden"> 
        <!-- 主内容区 -->
        <main class="flex-1 overflow-y-auto bg-gray-50 p-4 lg:p-6">
            <div class="container mx-auto">
                <!-- 面包屑导航 -->
                <div class="flex items-center text-sm text-gray-500 mb-4">
                    <a href="#" class="hover:text-primary">首页</a>
                    <i class="fa fa-angle-right mx-2 text-gray-300"></i>
                    <a href="#" class="hover:text-primary">教材版本管理</a>
                    <i class="fa fa-angle-right mx-2 text-gray-300"></i>
                    <span class="text-primary font-medium">添加新版本</span>
                </div>
                
                <!-- 内容标题区 -->
                <div class="flex flex-col md:flex-row md:items-center justify-between mb-6">
                    <div>
                        <h2 class="text-[clamp(1.5rem,3vw,2rem)] font-bold text-gray-800">添加新版本</h2>
                        <p class="text-gray-500 mt-1">创建新的教材版本并设置基本信息</p>
                    </div>
                    
                    <div class="flex space-x-3 mt-4 md:mt-0">
                        <button id="cancel-btn" class="bg-white border border-gray-300 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-50 transition-colors flex items-center">
                            <i class="fa fa-times mr-2"></i> 取消
                        </button>
                        <button id="save-version-btn" class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-primary/90 transition-colors flex items-center">
                            <i class="fa fa-save mr-2"></i> 保存版本
                        </button>
                    </div>
                </div>
                
                <!-- 版本表单 -->
                <div class="bg-white rounded-xl shadow-sm p-6 mb-6 fade-in">
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="font-bold text-lg">版本基本信息</h3>
                        <span class="text-sm text-gray-500">带 <span class="text-danger">*</span> 的为必填项</span>
                    </div>
                    
                    <form id="version-form" class="space-y-6">
                        <!-- 基础信息 -->
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div>
                                <label for="version-name" class="block text-sm font-medium text-gray-700 mb-1">
                                    版本名称 <span class="text-danger">*</span>
                                </label>
                                <input type="text" id="version-name" name="version-name" required
                                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                       placeholder="例如：人教版 2023版">
                            </div>
                            
                            <div>
                                <label for="subject" class="block text-sm font-medium text-gray-700 mb-1">
                                    所属学科 <span class="text-danger">*</span>
                                </label>
                                <select id="subject" name="subject" required
                                        class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all appearance-none bg-white">
                                    <option value="">请选择学科</option>
                                    <option value="math">数学</option>
                                    <option value="physics">物理</option>
                                    <option value="chemistry">化学</option>
                                    <option value="biology">生物</option>
                                    <option value="chinese">语文</option>
                                    <option value="english">英语</option>
                                    <option value="history">历史</option>
                                    <option value="geography">地理</option>
                                    <option value="politics">政治</option>
                                </select>
                            </div>
                            
                            <div>
                                <label for="publisher" class="block text-sm font-medium text-gray-700 mb-1">
                                    出版社 <span class="text-danger">*</span>
                                </label>
                                <input type="text" id="publisher" name="publisher" required
                                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                       placeholder="例如：人民教育出版社">
                            </div>
                            
                            <div>
                                <label for="publish-year" class="block text-sm font-medium text-gray-700 mb-1">
                                    出版年份 <span class="text-danger">*</span>
                                </label>
                                <input type="number" id="publish-year" name="publish-year" required min="1900" max="2099"
                                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                       placeholder="例如：2023">
                            </div>
                            
                            <div>
                                <label for="grade" class="block text-sm font-medium text-gray-700 mb-1">
                                    适用年级 <span class="text-danger">*</span>
                                </label>
                                <select id="grade" name="grade" required
                                        class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all appearance-none bg-white">
                                    <option value="">请选择年级</option>
                                    <option value="primary-1">小学一年级</option>
                                    <option value="primary-2">小学二年级</option>
                                    <option value="primary-3">小学三年级</option>
                                    <option value="primary-4">小学四年级</option>
                                    <option value="primary-5">小学五年级</option>
                                    <option value="primary-6">小学六年级</option>
                                    <option value="junior-1">初中一年级</option>
                                    <option value="junior-2">初中二年级</option>
                                    <option value="junior-3">初中三年级</option>
                                    <option value="senior-1">高中一年级</option>
                                    <option value="senior-2">高中二年级</option>
                                    <option value="senior-3">高中三年级</option>
                                </select>
                            </div>
                            
                            <div>
                                <label for="version-code" class="block text-sm font-medium text-gray-700 mb-1">
                                    版本编码
                                </label>
                                <input type="text" id="version-code" name="version-code"
                                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                       placeholder="系统自动生成（可自定义）">
                                <p class="mt-1 text-xs text-gray-500">用于系统内部标识，建议使用缩写+年份，如：RJ-2023</p>
                            </div>
                        </div>
                        
                        <!-- 封面上传 -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">
                                教材封面
                            </label>
                            <div class="mt-2 border-2 border-dashed border-gray-300 rounded-lg p-6 text-center hover:border-primary/50 transition-colors cursor-pointer" id="cover-upload-area">
                                <input type="file" id="cover-upload" class="hidden" accept="image/*">
                                <div class="space-y-2">
                                    <i class="fa fa-cloud-upload text-3xl text-gray-400"></i>
                                    <p class="text-sm text-gray-500">点击或拖拽文件到此处上传封面</p>
                                    <p class="text-xs text-gray-400">支持 JPG、PNG 格式，建议尺寸 300×400px</p>
                                </div>
                                <div id="cover-preview" class="hidden mt-4">
                                    <img id="cover-image" src="" alt="教材封面预览" class="max-h-40 mx-auto rounded-lg shadow-sm">
                                    <button type="button" id="remove-cover" class="mt-2 text-danger text-sm hover:underline">
                                        <i class="fa fa-times"></i> 移除封面
                                    </button>
                                </div>
                            </div>
                        </div>
                        
                        <!-- 教材介绍 -->
                        <div>
                            <label for="version-description" class="block text-sm font-medium text-gray-700 mb-1">
                                教材介绍
                            </label>
                            <textarea id="version-description" name="version-description" rows="4"
                                      class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                      placeholder="请简要描述本教材版本的特点、适用范围等信息"></textarea>
                        </div>
                        
                        <!-- 版本状态 -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">
                                版本状态
                            </label>
                            <div class="flex items-center space-x-4">
                                <label class="inline-flex items-center">
                                    <input type="radio" name="status" value="active" checked class="form-radio h-4 w-4 text-primary">
                                    <span class="ml-2 text-sm text-gray-700">启用</span>
                                </label>
                                <label class="inline-flex items-center">
                                    <input type="radio" name="status" value="inactive" class="form-radio h-4 w-4 text-primary">
                                    <span class="ml-2 text-sm text-gray-700">禁用</span>
                                </label>
                                <label class="inline-flex items-center">
                                    <input type="radio" name="status" value="draft" class="form-radio h-4 w-4 text-primary">
                                    <span class="ml-2 text-sm text-gray-700">草稿</span>
                                </label>
                            </div>
                        </div>
                    </form>
                </div>
                
                <!-- 章节结构管理 -->
                <div class="bg-white rounded-xl shadow-sm p-6 mb-6 fade-in" style="animation-delay: 0.1s">
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="font-bold text-lg">章节结构管理</h3>
                        <div class="flex space-x-3">
                            <button id="add-chapter-btn" class="text-sm bg-primary/10 text-primary px-3 py-1 rounded-lg hover:bg-primary/20 transition-colors flex items-center">
                                <i class="fa fa-plus mr-1"></i> 添加章节
                            </button>
                            <button id="import-chapters-btn" class="text-sm bg-gray-100 text-gray-600 px-3 py-1 rounded-lg hover:bg-gray-200 transition-colors flex items-center">
                                <i class="fa fa-upload mr-1"></i> 导入章节
                            </button>
                        </div>
                    </div>
                    
                    <div id="chapters-container" class="space-y-4">
                        <!-- 章节模板 - 默认显示一个空章节 -->
                        <div class="chapter-card border border-gray-200 rounded-lg overflow-hidden">
                            <div class="bg-gray-50 p-3 flex items-center justify-between">
                                <div class="flex items-center space-x-2">
                                    <button class="chapter-toggle text-gray-500 hover:text-primary transition-colors">
                                        <i class="fa fa-angle-down"></i>
                                    </button>
                                    <span class="font-medium">第1章</span>
                                </div>
                                <div class="flex space-x-2">
                                    <button class="text-gray-400 hover:text-primary transition-colors">
                                        <i class="fa fa-pencil"></i>
                                    </button>
                                    <button class="text-gray-400 hover:text-danger transition-colors">
                                        <i class="fa fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            
                            <div class="p-4">
                                <div class="mb-4">
                                    <label class="block text-sm font-medium text-gray-700 mb-1">
                                        章节标题 <span class="text-danger">*</span>
                                    </label>
                                    <input type="text" class="chapter-title w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                           placeholder="请输入章节标题">
                                </div>
                                
                                <div class="mb-4">
                                    <label class="block text-sm font-medium text-gray-700 mb-1">
                                        章节描述
                                    </label>
                                    <textarea class="chapter-description w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all" rows="2"
                                              placeholder="简要描述本章内容"></textarea>
                                </div>
                                
                                <div class="mb-4">
                                    <label class="block text-sm font-medium text-gray-700 mb-1">
                                        预计课时
                                    </label>
                                    <input type="number" class="chapter-hours w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                           min="1" max="100" placeholder="请输入预计课时数">
                                </div>
                                
                                <div class="section-list space-y-3">
                                    <div class="flex items-center justify-between mb-2">
                                        <h4 class="text-sm font-medium text-gray-600">小节列表</h4>
                                        <button class="add-section-btn text-xs bg-primary/10 text-primary px-2 py-1 rounded-lg hover:bg-primary/20 transition-colors">
                                            <i class="fa fa-plus"></i> 添加小节
                                        </button>
                                    </div>
                                    
                                    <!-- 小节模板 -->
                                    <div class="section-item border border-gray-100 rounded-lg p-3 hover:border-gray-200 transition-colors">
                                        <div class="flex items-center justify-between">
                                            <div class="flex items-center space-x-2">
                                                <button class="section-toggle text-gray-500 hover:text-primary transition-colors">
                                                    <i class="fa fa-angle-right"></i>
                                                </button>
                                                <span class="text-sm">1.1</span>
                                            </div>
                                            <div class="flex space-x-2">
                                                <button class="text-gray-400 hover:text-primary transition-colors">
                                                    <i class="fa fa-pencil"></i>
                                                </button>
                                                <button class="text-gray-400 hover:text-danger transition-colors">
                                                    <i class="fa fa-trash"></i>
                                                </button>
                                            </div>
                                        </div>
                                        
                                        <div class="mt-2 pl-4 hidden section-content">
                                            <div class="mb-3">
                                                <label class="block text-xs font-medium text-gray-600 mb-1">
                                                    小节标题 <span class="text-danger">*</span>
                                                </label>
                                                <input type="text" class="section-title w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                                       placeholder="请输入小节标题">
                                            </div>
                                            
                                            <div class="mb-3">
                                                <label class="block text-xs font-medium text-gray-600 mb-1">
                                                    小节描述
                                                </label>
                                                <textarea class="section-description w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all" rows="1"
                                                         placeholder="简要描述本小节内容"></textarea>
                                            </div>
                                            
                                            <div class="mb-3">
                                                <label class="block text-xs font-medium text-gray-600 mb-1">
                                                    预计课时
                                                </label>
                                                <input type="number" class="section-hours w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                                       min="1" max="50" placeholder="请输入预计课时数">
                                            </div>
                                            
                                            <div class="subsection-list space-y-2 pl-4">
                                                <div class="flex items-center justify-between mb-1">
                                                    <h5 class="text-xs font-medium text-gray-500">知识点列表</h5>
                                                    <button class="add-subsection-btn text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded hover:bg-primary/20 transition-colors">
                                                        <i class="fa fa-plus"></i> 添加知识点
                                                    </button>
                                                </div>
                                                
                                                <!-- 知识点模板 -->
                                                <div class="subsection-item border-l-2 border-dashed border-gray-200 pl-3 py-1">
                                                    <div class="flex items-center justify-between">
                                                        <div class="flex items-center space-x-1">
                                                            <span class="text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded">知</span>
                                                            <input type="text" class="subsection-title text-xs w-48 border-none focus:ring-0"
                                                                   placeholder="请输入知识点名称">
                                                        </div>
                                                        <div class="flex space-x-1">
                                                            <button class="text-gray-400 hover:text-primary transition-colors text-xs">
                                                                <i class="fa fa-pencil"></i>
                                                            </button>
                                                            <button class="text-gray-400 hover:text-danger transition-colors text-xs">
                                                                <i class="fa fa-trash"></i>
                                                            </button>
                                                        </div>
                                                    </div>
                                                </div>
                                                <!-- 知识点模板结束 -->
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 小节模板结束 -->
                                </div>
                            </div>
                        </div>
                        <!-- 章节模板结束 -->
                    </div>
                </div>
                
                <!-- 版本对比设置 -->
                <div class="bg-white rounded-xl shadow-sm p-6 mb-6 fade-in" style="animation-delay: 0.2s">
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="font-bold text-lg">版本对比设置</h3>
                        <div class="flex items-center space-x-2">
                            <span class="text-xs bg-blue-100 text-blue-600 px-2 py-0.5 rounded-full">可选</span>
                        </div>
                    </div>
                    
                    <div>
                        <p class="text-sm text-gray-600 mb-4">选择一个已有的版本作为参考，系统将自动对比并标记新增、修改和删除的内容</p>
                        
                        <div class="relative mb-4">
                            <select id="compare-version" class="w-full appearance-none bg-gray-50 border border-gray-200 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary">
                                <option value="">不与其他版本对比</option>
                                <option value="RJ-2022">人教版 2022版</option>
                                <option value="SX-2022">苏教版 2022版</option>
                                <option value="BS-2022">北师大版 2022版</option>
                            </select>
                            <i class="fa fa-chevron-down absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 pointer-events-none"></i>
                        </div>
                        
                        <div id="comparison-result" class="hidden mt-4 p-4 bg-gray-50 rounded-lg border border-gray-200">
                            <h4 class="font-medium text-gray-700 mb-2">对比结果</h4>
                            <div class="space-y-2 text-sm">
                                <div class="flex items-center">
                                    <span class="inline-block w-3 h-3 rounded-full bg-green-100 border border-green-400 mr-2"></span>
                                    <span>新增章节：2个</span>
                                </div>
                                <div class="flex items-center">
                                    <span class="inline-block w-3 h-3 rounded-full bg-yellow-100 border border-yellow-400 mr-2"></span>
                                    <span>修改章节：3个</span>
                                </div>
                                <div class="flex items-center">
                                    <span class="inline-block w-3 h-3 rounded-full bg-red-100 border border-red-400 mr-2"></span>
                                    <span>删除章节：1个</span>
                                </div>
                                <div class="flex items-center">
                                    <span class="inline-block w-3 h-3 rounded-full bg-blue-100 border border-blue-400 mr-2"></span>
                                    <span>新增知识点：15个</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 页脚操作按钮 -->
                <div class="sticky bottom-0 bg-white bg-opacity-90 backdrop-blur-sm p-4 rounded-xl shadow-md mt-6">
                    <div class="flex items-center justify-end space-x-3">
                        <button id="cancel-footer-btn" class="bg-white border border-gray-300 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-50 transition-colors flex items-center">
                            <i class="fa fa-times mr-2"></i> 取消
                        </button>
                        <button id="save-draft-btn" class="bg-gray-100 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-200 transition-colors flex items-center">
                            <i class="fa fa-save mr-2"></i> 保存为草稿
                        </button>
                        <button id="save-version-footer-btn" class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-primary/90 transition-colors flex items-center">
                            <i class="fa fa-check mr-2"></i> 保存并启用
                        </button>
                    </div>
                </div>
            </div>
        </main>
    </div>
    
    <!-- 确认对话框 -->
    <div id="confirm-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-xl shadow-lg p-6 max-w-md w-full mx-4">
            <div class="text-center mb-4">
                <div class="inline-flex items-center justify-center w-12 h-12 rounded-full bg-yellow-100 text-yellow-500 mb-4">
                    <i class="fa fa-exclamation-triangle text-xl"></i>
                </div>
                <h3 class="text-lg font-bold text-gray-900">确认操作</h3>
                <p class="text-gray-600 mt-2" id="confirm-message">您确定要执行此操作吗？</p>
            </div>
            <div class="flex space-x-3 mt-6">
                <button id="confirm-cancel" class="flex-1 bg-white border border-gray-300 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-50 transition-colors">
                    取消
                </button>
                <button id="confirm-ok" class="flex-1 bg-primary text-white px-4 py-2 rounded-lg hover:bg-primary/90 transition-colors">
                    确认
                </button>
            </div>
        </div>
    </div>
    
    <!-- 成功提示框 -->
    <div id="success-toast" class="fixed bottom-4 right-4 bg-success text-white px-4 py-3 rounded-lg shadow-lg transform translate-y-16 opacity-0 transition-all duration-500 z-50 flex items-center">
        <i class="fa fa-check-circle mr-2"></i>
        <span id="success-message">操作成功</span>
    </div>
    
    <!-- 错误提示框 -->
    <div id="error-toast" class="fixed bottom-4 right-4 bg-danger text-white px-4 py-3 rounded-lg shadow-lg transform translate-y-16 opacity-0 transition-all duration-500 z-50 flex items-center">
        <i class="fa fa-times-circle mr-2"></i>
        <span id="error-message">操作失败</span>
    </div>

        <!-- 页脚 -->
    <footer class="bg-white border-t border-gray-200 py-4">
        <div class="container mx-auto px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="text-center md:text-left mb-4 md:mb-0">
                    <p class="text-sm text-gray-500">© 2025 教材资源管理系统. 保留所有权利.</p>
                </div>
                <div class="flex space-x-6">
                    <a href="#" class="text-gray-500 hover:text-primary transition-colors">
                        <i class="fa fa-question-circle mr-1"></i> 帮助中心
                    </a>
                    <a href="#" class="text-gray-500 hover:text-primary transition-colors">
                        <i class="fa fa-file-text-o mr-1"></i> 使用条款
                    </a>
                    <a href="#" class="text-gray-500 hover:text-primary transition-colors">
                        <i class="fa fa-shield mr-1"></i> 隐私政策
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        // 侧边栏切换
        document.getElementById('sidebar-toggle').addEventListener('click', function() {
            const sidebar = document.getElementById('sidebar');
            sidebar.classList.toggle('-translate-x-full');
        });
        
        // 章节展开/收起
        document.querySelectorAll('.chapter-toggle').forEach(toggle => {
            toggle.addEventListener('click', function() {
                const chapterCard = this.closest('.chapter-card');
                const content = chapterCard.querySelector('.p-4');
                const icon = this.querySelector('i');
                
                content.classList.toggle('hidden');
                if (content.classList.contains('hidden')) {
                    icon.classList.remove('fa-angle-down');
                    icon.classList.add('fa-angle-right');
                } else {
                    icon.classList.remove('fa-angle-right');
                    icon.classList.add('fa-angle-down');
                }
            });
        });
        
        // 小节展开/收起
        document.querySelectorAll('.section-toggle').forEach(toggle => {
            toggle.addEventListener('click', function() {
                const sectionItem = this.closest('.section-item');
                const content = sectionItem.querySelector('.section-content');
                const icon = this.querySelector('i');
                
                content.classList.toggle('hidden');
                if (content.classList.contains('hidden')) {
                    icon.classList.remove('fa-angle-down');
                    icon.classList.add('fa-angle-right');
                } else {
                    icon.classList.remove('fa-angle-right');
                    icon.classList.add('fa-angle-down');
                }
            });
        });
        
        // 封面上传
        const coverUpload = document.getElementById('cover-upload');
        const coverUploadArea = document.getElementById('cover-upload-area');
        const coverPreview = document.getElementById('cover-preview');
        const coverImage = document.getElementById('cover-image');
        const removeCover = document.getElementById('remove-cover');
        
        coverUploadArea.addEventListener('click', () => {
            coverUpload.click();
        });
        
        coverUpload.addEventListener('change', function() {
            if (this.files && this.files[0]) {
                const reader = new FileReader();
                
                reader.onload = function(e) {
                    coverImage.src = e.target.result;
                    coverPreview.classList.remove('hidden');
                }
                
                reader.readAsDataURL(this.files[0]);
            }
        });
        
        removeCover.addEventListener('click', function() {
            coverImage.src = '';
            coverPreview.classList.add('hidden');
            coverUpload.value = '';
        });
        
        // 添加章节按钮
        document.getElementById('add-chapter-btn').addEventListener('click', function() {
            const chaptersContainer = document.getElementById('chapters-container');
            const chapterCards = chaptersContainer.querySelectorAll('.chapter-card');
            const newChapterNumber = chapterCards.length + 1;
            
            const newChapter = document.createElement('div');
            newChapter.className = 'chapter-card border border-gray-200 rounded-lg overflow-hidden';
            newChapter.innerHTML = `
                <div class="bg-gray-50 p-3 flex items-center justify-between">
                    <div class="flex items-center space-x-2">
                        <button class="chapter-toggle text-gray-500 hover:text-primary transition-colors">
                            <i class="fa fa-angle-down"></i>
                        </button>
                        <span class="font-medium">第${newChapterNumber}章</span>
                    </div>
                    <div class="flex space-x-2">
                        <button class="text-gray-400 hover:text-primary transition-colors">
                            <i class="fa fa-pencil"></i>
                        </button>
                        <button class="text-gray-400 hover:text-danger transition-colors delete-chapter">
                            <i class="fa fa-trash"></i>
                        </button>
                    </div>
                </div>
                
                <div class="p-4">
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">
                            章节标题 <span class="text-danger">*</span>
                        </label>
                        <input type="text" class="chapter-title w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                               placeholder="请输入章节标题">
                    </div>
                    
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">
                            章节描述
                        </label>
                        <textarea class="chapter-description w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all" rows="2"
                                  placeholder="简要描述本章内容"></textarea>
                    </div>
                    
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">
                            预计课时
                        </label>
                        <input type="number" class="chapter-hours w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                               min="1" max="100" placeholder="请输入预计课时数">
                    </div>
                    
                    <div class="section-list space-y-3">
                        <div class="flex items-center justify-between mb-2">
                            <h4 class="text-sm font-medium text-gray-600">小节列表</h4>
                            <button class="add-section-btn text-xs bg-primary/10 text-primary px-2 py-1 rounded-lg hover:bg-primary/20 transition-colors">
                                <i class="fa fa-plus"></i> 添加小节
                            </button>
                        </div>
                        
                        <!-- 小节模板 -->
                        <div class="section-item border border-gray-100 rounded-lg p-3 hover:border-gray-200 transition-colors">
                            <div class="flex items-center justify-between">
                                <div class="flex items-center space-x-2">
                                    <button class="section-toggle text-gray-500 hover:text-primary transition-colors">
                                        <i class="fa fa-angle-right"></i>
                                    </button>
                                    <span class="text-sm">${newChapterNumber}.1</span>
                                </div>
                                <div class="flex space-x-2">
                                    <button class="text-gray-400 hover:text-primary transition-colors">
                                        <i class="fa fa-pencil"></i>
                                    </button>
                                    <button class="text-gray-400 hover:text-danger transition-colors">
                                        <i class="fa fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            
                            <div class="mt-2 pl-4 hidden section-content">
                                <div class="mb-3">
                                    <label class="block text-xs font-medium text-gray-600 mb-1">
                                        小节标题 <span class="text-danger">*</span>
                                    </label>
                                    <input type="text" class="section-title w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                           placeholder="请输入小节标题">
                                </div>
                                
                                <div class="mb-3">
                                    <label class="block text-xs font-medium text-gray-600 mb-1">
                                        小节描述
                                    </label>
                                    <textarea class="section-description w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all" rows="1"
                                             placeholder="简要描述本小节内容"></textarea>
                                </div>
                                
                                <div class="mb-3">
                                    <label class="block text-xs font-medium text-gray-600 mb-1">
                                        预计课时
                                    </label>
                                    <input type="number" class="section-hours w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                           min="1" max="50" placeholder="请输入预计课时数">
                                </div>
                                





                                <div class="subsection-list space-y-2 pl-4">
                                    <div class="flex items-center justify-between mb-1">
                                        <h5 class="text-xs font-medium text-gray-500">知识点列表</h5>
                                        <button class="add-subsection-btn text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded hover:bg-primary/20 transition-colors">
                                            <i class="fa fa-plus"></i> 添加知识点
                                        </button>
                                    </div>
                                    
                                    <!-- 知识点模板 -->
                                    <div class="subsection-item border-l-2 border-dashed border-gray-200 pl-3 py-1">
                                        <div class="flex items-center justify-between">
                                            <div class="flex items-center space-x-1">
                                                <span class="text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded">知</span>
                                                <input type="text" class="subsection-title text-xs w-48 border-none focus:ring-0"
                                                       placeholder="请输入知识点名称">
                                            </div>
                                            <div class="flex space-x-1">
                                                <button class="text-gray-400 hover:text-primary transition-colors text-xs">
                                                    <i class="fa fa-pencil"></i>
                                                </button>
                                                <button class="text-gray-400 hover:text-danger transition-colors text-xs">
                                                    <i class="fa fa-trash"></i>
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 知识点模板结束 -->
                                </div>
                            </div>
                        </div>
                        <!-- 小节模板结束 -->
                    </div>
                </div>
            `;
            
            chaptersContainer.appendChild(newChapter);
            
            // 为新章节添加事件监听
            newChapter.querySelector('.chapter-toggle').addEventListener('click', function() {
                const content = this.closest('.chapter-card').querySelector('.p-4');
                const icon = this.querySelector('i');
                
                content.classList.toggle('hidden');
                if (content.classList.contains('hidden')) {
                    icon.classList.remove('fa-angle-down');
                    icon.classList.add('fa-angle-right');
                } else {
                    icon.classList.remove('fa-angle-right');
                    icon.classList.add('fa-angle-down');
                }
            });
            
            // 为新章节的删除按钮添加事件监听
            newChapter.querySelector('.delete-chapter').addEventListener('click', function() {
                showConfirm('确定要删除这个章节吗？删除后将无法恢复。', function() {
                    newChapter.remove();
                    updateChapterNumbers();
                    showSuccessToast('章节已成功删除');
                });
            });
            
            // 为新章节的添加小节按钮添加事件监听
            newChapter.querySelector('.add-section-btn').addEventListener('click', function() {
                const sectionList = this.closest('.section-list');
                const sectionItems = sectionList.querySelectorAll('.section-item');
                const chapterNumber = this.closest('.chapter-card').querySelector('.font-medium').textContent.replace('第', '').replace('章', '');
                const newSectionNumber = sectionItems.length + 1;
                
                const newSection = document.createElement('div');
                newSection.className = 'section-item border border-gray-100 rounded-lg p-3 hover:border-gray-200 transition-colors';
                newSection.innerHTML = `
                    <div class="flex items-center justify-between">
                        <div class="flex items-center space-x-2">
                            <button class="section-toggle text-gray-500 hover:text-primary transition-colors">
                                <i class="fa fa-angle-right"></i>
                            </button>
                            <span class="text-sm">${chapterNumber}.${newSectionNumber}</span>
                        </div>
                        <div class="flex space-x-2">
                            <button class="text-gray-400 hover:text-primary transition-colors">
                                <i class="fa fa-pencil"></i>
                            </button>
                            <button class="text-gray-400 hover:text-danger transition-colors delete-section">
                                <i class="fa fa-trash"></i>
                            </button>
                        </div>
                    </div>
                    
                    <div class="mt-2 pl-4 hidden section-content">
                        <div class="mb-3">
                            <label class="block text-xs font-medium text-gray-600 mb-1">
                                小节标题 <span class="text-danger">*</span>
                            </label>
                            <input type="text" class="section-title w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                   placeholder="请输入小节标题">
                        </div>
                        
                        <div class="mb-3">
                            <label class="block text-xs font-medium text-gray-600 mb-1">
                                小节描述
                            </label>
                            <textarea class="section-description w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all" rows="1"
                                     placeholder="简要描述本小节内容"></textarea>
                        </div>
                        
                        <div class="mb-3">
                            <label class="block text-xs font-medium text-gray-600 mb-1">
                                预计课时
                            </label>
                            <input type="number" class="section-hours w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                   min="1" max="50" placeholder="请输入预计课时数">
                        </div>
                        
                        <div class="subsection-list space-y-2 pl-4">
                            <div class="flex items-center justify-between mb-1">
                                <h5 class="text-xs font-medium text-gray-500">知识点列表</h5>
                                <button class="add-subsection-btn text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded hover:bg-primary/20 transition-colors">
                                    <i class="fa fa-plus"></i> 添加知识点
                                </button>
                            </div>
                            
                            <!-- 知识点模板 -->
                            <div class="subsection-item border-l-2 border-dashed border-gray-200 pl-3 py-1">
                                <div class="flex items-center justify-between">
                                    <div class="flex items-center space-x-1">
                                        <span class="text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded">知</span>
                                        <input type="text" class="subsection-title text-xs w-48 border-none focus:ring-0"
                                               placeholder="请输入知识点名称">
                                    </div>
                                    <div class="flex space-x-1">
                                        <button class="text-gray-400 hover:text-primary transition-colors text-xs">
                                            <i class="fa fa-pencil"></i>
                                        </button>
                                        <button class="text-gray-400 hover:text-danger transition-colors text-xs">
                                            <i class="fa fa-trash"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                            <!-- 知识点模板结束 -->
                        </div>
                    </div>
                `;
                
                sectionList.appendChild(newSection);
                
                // 为新小节添加事件监听
                newSection.querySelector('.section-toggle').addEventListener('click', function() {
                    const content = this.closest('.section-item').querySelector('.section-content');
                    const icon = this.querySelector('i');
                    
                    content.classList.toggle('hidden');
                    if (content.classList.contains('hidden')) {
                        icon.classList.remove('fa-angle-down');
                        icon.classList.add('fa-angle-right');
                    } else {
                        icon.classList.remove('fa-angle-right');
                        icon.classList.add('fa-angle-down');
                    }
                });
                
                // 为新小节的删除按钮添加事件监听
                newSection.querySelector('.delete-section').addEventListener('click', function() {
                    showConfirm('确定要删除这个小节吗？删除后将无法恢复。', function() {
                        newSection.remove();
                        updateSectionNumbers();
                        showSuccessToast('小节已成功删除');
                    });
                });
                
                // 为新小节的添加知识点按钮添加事件监听
                newSection.querySelector('.add-subsection-btn').addEventListener('click', function() {
                    const subsectionList = this.closest('.subsection-list');
                    const subsectionItems = subsectionList.querySelectorAll('.subsection-item');
                    
                    const newSubsection = document.createElement('div');
                    newSubsection.className = 'subsection-item border-l-2 border-dashed border-gray-200 pl-3 py-1';
                    newSubsection.innerHTML = `
                        <div class="flex items-center justify-between">
                            <div class="flex items-center space-x-1">
                                <span class="text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded">知</span>
                                <input type="text" class="subsection-title text-xs w-48 border-none focus:ring-0"
                                       placeholder="请输入知识点名称">
                            </div>
                            <div class="flex space-x-1">
                                <button class="text-gray-400 hover:text-primary transition-colors text-xs">
                                    <i class="fa fa-pencil"></i>
                                </button>
                                <button class="text-gray-400 hover:text-danger transition-colors text-xs delete-subsection">
                                    <i class="fa fa-trash"></i>
                                </button>
                            </div>
                        </div>
                    `;
                    
                    subsectionList.appendChild(newSubsection);
                    
                    // 为新知识点的删除按钮添加事件监听
                    newSubsection.querySelector('.delete-subsection').addEventListener('click', function() {
                        showConfirm('确定要删除这个知识点吗？删除后将无法恢复。', function() {
                            newSubsection.remove();
                            showSuccessToast('知识点已成功删除');
                        });
                    });
                });
            });
        });
        
        // 为现有章节的删除按钮添加事件监听
        document.querySelectorAll('.delete-chapter').forEach(button => {
            button.addEventListener('click', function() {
                const chapterCard = this.closest('.chapter-card');
                showConfirm('确定要删除这个章节吗？删除后将无法恢复。', function() {
                    chapterCard.remove();
                    updateChapterNumbers();
                    showSuccessToast('章节已成功删除');
                });
            });
        });
        
        // 为现有小节的删除按钮添加事件监听
        document.querySelectorAll('.delete-section').forEach(button => {
            button.addEventListener('click', function() {
                const sectionItem = this.closest('.section-item');
                showConfirm('确定要删除这个小节吗？删除后将无法恢复。', function() {
                    sectionItem.remove();
                    updateSectionNumbers();
                    showSuccessToast('小节已成功删除');
                });
            });
        });
        
        // 为现有知识点的删除按钮添加事件监听
        document.querySelectorAll('.delete-subsection').forEach(button => {
            button.addEventListener('click', function() {
                const subsectionItem = this.closest('.subsection-item');
                showConfirm('确定要删除这个知识点吗？删除后将无法恢复。', function() {
                    subsectionItem.remove();
                    showSuccessToast('知识点已成功删除');
                });
            });
        });
        
        // 为现有添加小节按钮添加事件监听
        document.querySelectorAll('.add-section-btn').forEach(button => {
            button.addEventListener('click', function() {
                const sectionList = this.closest('.section-list');
                const sectionItems = sectionList.querySelectorAll('.section-item');
                const chapterNumber = this.closest('.chapter-card').querySelector('.font-medium').textContent.replace('第', '').replace('章', '');
                const newSectionNumber = sectionItems.length + 1;
                
                const newSection = document.createElement('div');
                newSection.className = 'section-item border border-gray-100 rounded-lg p-3 hover:border-gray-200 transition-colors';
                newSection.innerHTML = `
                    <div class="flex items-center justify-between">
                        <div class="flex items-center space-x-2">
                            <button class="section-toggle text-gray-500 hover:text-primary transition-colors">
                                <i class="fa fa-angle-right"></i>
                            </button>
                            <span class="text-sm">${chapterNumber}.${newSectionNumber}</span>
                        </div>
                        <div class="flex space-x-2">
                            <button class="text-gray-400 hover:text-primary transition-colors">
                                <i class="fa fa-pencil"></i>
                            </button>
                            <button class="text-gray-400 hover:text-danger transition-colors delete-section">
                                <i class="fa fa-trash"></i>
                            </button>
                        </div>
                    </div>
                    
                    <div class="mt-2 pl-4 hidden section-content">
                        <div class="mb-3">
                            <label class="block text-xs font-medium text-gray-600 mb-1">
                                小节标题 <span class="text-danger">*</span>
                            </label>
                            <input type="text" class="section-title w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                   placeholder="请输入小节标题">
                        </div>
                        
                        <div class="mb-3">
                            <label class="block text-xs font-medium text-gray-600 mb-1">
                                小节描述
                            </label>
                            <textarea class="section-description w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all" rows="1"
                                     placeholder="简要描述本小节内容"></textarea>
                        </div>
                        
                        <div class="mb-3">
                            <label class="block text-xs font-medium text-gray-600 mb-1">
                                预计课时
                            </label>
                            <input type="number" class="section-hours w-full px-3 py-1.5 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all"
                                   min="1" max="50" placeholder="请输入预计课时数">
                        </div>
                        
                        <div class="subsection-list space-y-2 pl-4">
                            <div class="flex items-center justify-between mb-1">
                                <h5 class="text-xs font-medium text-gray-500">知识点列表</h5>
                                <button class="add-subsection-btn text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded hover:bg-primary/20 transition-colors">
                                    <i class="fa fa-plus"></i> 添加知识点
                                </button>
                            </div>
                            
                            <!-- 知识点模板 -->
                            <div class="subsection-item border-l-2 border-dashed border-gray-200 pl-3 py-1">
                                <div class="flex items-center justify-between">
                                    <div class="flex items-center space-x-1">
                                        <span class="text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded">知</span>
                                        <input type="text" class="subsection-title text-xs w-48 border-none focus:ring-0"
                                               placeholder="请输入知识点名称">
                                    </div>
                                    <div class="flex space-x-1">
                                        <button class="text-gray-400 hover:text-primary transition-colors text-xs">
                                            <i class="fa fa-pencil"></i>
                                        </button>
                                        <button class="text-gray-400 hover:text-danger transition-colors text-xs delete-subsection">
                                            <i class="fa fa-trash"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                            <!-- 知识点模板结束 -->
                        </div>
                    </div>
                `;
                
                sectionList.appendChild(newSection);
                
                // 为新小节添加事件监听
                newSection.querySelector('.section-toggle').addEventListener('click', function() {
                    const content = this.closest('.section-item').querySelector('.section-content');
                    const icon = this.querySelector('i');
                    
                    content.classList.toggle('hidden');
                    if (content.classList.contains('hidden')) {
                        icon.classList.remove('fa-angle-down');
                        icon.classList.add('fa-angle-right');
                    } else {
                        icon.classList.remove('fa-angle-right');
                        icon.classList.add('fa-angle-down');
                    }
                });
                
                // 为新小节的删除按钮添加事件监听
                newSection.querySelector('.delete-section').addEventListener('click', function() {
                    showConfirm('确定要删除这个小节吗？删除后将无法恢复。', function() {
                        newSection.remove();
                        updateSectionNumbers();
                        showSuccessToast('小节已成功删除');
                    });
                });
                
                // 为新小节的添加知识点按钮添加事件监听
                newSection.querySelector('.add-subsection-btn').addEventListener('click', function() {
                    const subsectionList = this.closest('.subsection-list');
                    const subsectionItems = subsectionList.querySelectorAll('.subsection-item');
                    
                    const newSubsection = document.createElement('div');
                    newSubsection.className = 'subsection-item border-l-2 border-dashed border-gray-200 pl-3 py-1';
                    newSubsection.innerHTML = `
                        <div class="flex items-center justify-between">
                            <div class="flex items-center space-x-1">
                                <span class="text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded">知</span>
                                <input type="text" class="subsection-title text-xs w-48 border-none focus:ring-0"
                                       placeholder="请输入知识点名称">
                            </div>
                            <div class="flex space-x-1">
                                <button class="text-gray-400 hover:text-primary transition-colors text-xs">
                                    <i class="fa fa-pencil"></i>
                                </button>
                                <button class="text-gray-400 hover:text-danger transition-colors text-xs delete-subsection">
                                    <i class="fa fa-trash"></i>
                                </button>
                            </div>
                        </div>
                    `;
                    
                    subsectionList.appendChild(newSubsection);
                    
                    // 为新知识点的删除按钮添加事件监听
                    newSubsection.querySelector('.delete-subsection').addEventListener('click', function() {
                        showConfirm('确定要删除这个知识点吗？删除后将无法恢复。', function() {
                            newSubsection.remove();
                            showSuccessToast('知识点已成功删除');
                        });
                    });
                });
            });
        });
        
        // 为现有添加知识点按钮添加事件监听
        document.querySelectorAll('.add-subsection-btn').forEach(button => {
            button.addEventListener('click', function() {
                const subsectionList = this.closest('.subsection-list');
                const subsectionItems = subsectionList.querySelectorAll('.subsection-item');
                
                const newSubsection = document.createElement('div');
                newSubsection.className = 'subsection-item border-l-2 border-dashed border-gray-200 pl-3 py-1';
                newSubsection.innerHTML = `
                    <div class="flex items-center justify-between">
                        <div class="flex items-center space-x-1">
                            <span class="text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded">知</span>
                            <input type="text" class="subsection-title text-xs w-48 border-none focus:ring-0"
                                   placeholder="请输入知识点名称">
                        </div>
                        <div class="flex space-x-1">
                            <button class="text-gray-400 hover:text-primary transition-colors text-xs">
                                <i class="fa fa-pencil"></i>
                            </button>
                            <button class="text-gray-400 hover:text-danger transition-colors text-xs delete-subsection">
                                <i class="fa fa-trash"></i>
                            </button>
                        </div>
                    </div>
                `;
                
                subsectionList.appendChild(newSubsection);
                
                // 为新知识点的删除按钮添加事件监听
                newSubsection.querySelector('.delete-subsection').addEventListener('click', function() {
                    showConfirm('确定要删除这个知识点吗？删除后将无法恢复。', function() {
                        newSubsection.remove();
                        showSuccessToast('知识点已成功删除');
                    });
                });
            });
        });
        
        // 版本对比选择
        document.getElementById('compare-version').addEventListener('change', function() {
            const comparisonResult = document.getElementById('comparison-result');
            if (this.value) {
                comparisonResult.classList.remove('hidden');
            } else {
                comparisonResult.classList.add('hidden');
            }
        });
        
        // 保存版本按钮
        document.getElementById('save-version-btn').addEventListener('click', function() {
            saveVersion();
        });
        
        document.getElementById('save-version-footer-btn').addEventListener('click', function() {
            saveVersion();
        });
        
        // 保存为草稿按钮
        document.getElementById('save-draft-btn').addEventListener('click', function() {
            saveVersion('draft');
        });
        
        // 取消按钮
        document.getElementById('cancel-btn').addEventListener('click', function() {
            showConfirm('确定要取消吗？未保存的内容将会丢失。', function() {
                window.history.back();
            });
        });
        
        document.getElementById('cancel-footer-btn').addEventListener('click', function() {
            showConfirm('确定要取消吗？未保存的内容将会丢失。', function() {
                window.history.back();
            });
        });
        
        // 导入章节按钮
        document.getElementById('import-chapters-btn').addEventListener('click', function() {
            showConfirm('确定要导入章节结构吗？当前已添加的章节将被覆盖。', function() {
                // 模拟导入成功
                setTimeout(function() {
                    showSuccessToast('章节结构导入成功');
                }, 500);
            });
        });
        
        // 保存版本函数
        function saveVersion(status = 'active') {
            // 这里可以添加表单验证逻辑
            
            // 显示成功提示
            showSuccessToast(status === 'draft' ? '版本已保存为草稿' : '版本保存成功并已启用');
            
            // 模拟保存成功后延迟返回
            setTimeout(function() {
                window.history.back();
            }, 1500);
        }
        
        // 更新章节编号
        function updateChapterNumbers() {
            const chaptersContainer = document.getElementById('chapters-container');
            const chapterCards = chaptersContainer.querySelectorAll('.chapter-card');
            
            chapterCards.forEach((card, index) => {
                const chapterNumber = index + 1;
                card.querySelector('.font-medium').textContent = `第${chapterNumber}章`;
                
                // 更新小节编号
                const sectionItems = card.querySelectorAll('.section-item');
                sectionItems.forEach((section, sectionIndex) => {
                    const sectionNumber = sectionIndex + 1;
                    section.querySelector('.text-sm').textContent = `${chapterNumber}.${sectionNumber}`;
                });
            });
        }
        
        // 更新小节编号
        function updateSectionNumbers() {
            const chapterCards = document.querySelectorAll('.chapter-card');
            
            chapterCards.forEach((card, chapterIndex) => {
                const chapterNumber = chapterIndex + 1;
                const sectionItems = card.querySelectorAll('.section-item');
                
                sectionItems.forEach((section, sectionIndex) => {
                    const sectionNumber = sectionIndex + 1;
                    section.querySelector('.text-sm').textContent = `${chapterNumber}.${sectionNumber}`;
                });
            });
        }
        
        // 显示确认对话框
        function showConfirm(message, callback) {
            const confirmModal = document.getElementById('confirm-modal');
            const confirmMessage = document.getElementById('confirm-message');
            const confirmOk = document.getElementById('confirm-ok');
            const confirmCancel = document.getElementById('confirm-cancel');
            
            confirmMessage.textContent = message;
            confirmModal.classList.remove('hidden');
            
            const confirmHandler = function() {
                callback();
                confirmModal.classList.add('hidden');
                confirmOk.removeEventListener('click', confirmHandler);
                confirmCancel.removeEventListener('click', cancelHandler);
            };
            
            const cancelHandler = function() {
                confirmModal.classList.add('hidden');
                confirmOk.removeEventListener('click', confirmHandler);
                confirmCancel.removeEventListener('click', cancelHandler);
            };
            
            confirmOk.addEventListener('click', confirmHandler);
            confirmCancel.addEventListener('click', cancelHandler);
        }
        
        // 显示成功提示框
        function showSuccessToast(message) {
            const successToast = document.getElementById('success-toast');
            const successMessage = document.getElementById('success-message');
            
            successMessage.textContent = message;
            successToast.classList.remove('translate-y-16', 'opacity-0');
            
            setTimeout(function() {
                successToast.classList.add('translate-y-16', 'opacity-0');
            }, 3000);
        }
        
        // 显示错误提示框
        function showErrorToast(message) {
            const errorToast = document.getElementById('error-toast');
            const errorMessage = document.getElementById('error-message');
            
            errorMessage.textContent = message;
            errorToast.classList.remove('translate-y-16', 'opacity-0');
            
            setTimeout(function() {
                errorToast.classList.add('translate-y-16', 'opacity-0');
            }, 3000);
        }
        
        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', function() {
            // 初始化章节展开/收起状态
            document.querySelectorAll('.chapter-toggle').forEach(toggle => {
                toggle.click(); // 默认展开所有章节
            });
            
            // 初始化小节展开/收起状态
            document.querySelectorAll('.section-toggle').forEach(toggle => {
                // 默认收起所有小节
                const content = toggle.closest('.section-item').querySelector('.section-content');
                const icon = toggle.querySelector('i');
                
                content.classList.add('hidden');
                icon.classList.remove('fa-angle-down');
                icon.classList.add('fa-angle-right');
            });
        });
    </script>
</body>
</html>
                                